
var api = require('../../utils/api.js');
var app = getApp();
var WxParse = require('../../wxParse/wxParse.js');
Page({
    data: {
        tophe:0,
        info:[]
    },
    currentPageNumber: 1,
        onLoad(ret) {
            console.log('分享场景值:', ret);
            var file=api.FIlE;
            this.setData({
                bg:file
            })

            if (ret && ret.scene) {
            // 处理扫码进入时的场景值
                console.log('分享场景值:', ret.scene);
                this.setData({
                    id:ret.scene
                })
            }
      
          if (ret && ret.id) {
            console.log('直接进入:', ret.id);
            this.setData({
                id:ret.id
            })
          }



       this.getinfobyid();
       this.getusrinfo();
    },
    back(){
        wx.navigateBack()
    },
    onShow() {
        let jn = wx.getMenuButtonBoundingClientRect();

        console.log(jn);
        var tophe=jn.top+jn.height+80;
        this.setData({
            tophe:tophe+'px',
            over:jn.top
        })
     
    },
      // 获取详情
      getinfobyid(){
        var that=this;
        var id=this.data.id;

        api.post({
            url: 'meeting/getmeetbyid',
            data: {id:id},
            success: data => {

                that.setData({
                    htmlSnip:that.formatRichText(data.data.content),
                    meet:data.data
                })
         
            },
        });
    },

    getusrinfo(){
        var that=this;
        api.post({
            url: 'user/index',
            data: {},
            success: data => {
                // 使用WxParse解析富文本内容
                that.setData({
                    user:data.data
                })
            },
        });
    },
    gohouse(){

        var info=this.data.info;


        wx.openLocation({
          latitude: parseFloat(info.lat), // 纬度
          longitude: parseFloat(info.lng), // 经度
          name: '金牛宾馆', // 位置名称
          scale: 28, // 缩放比例
          success: function () {
            console.log('地图打开成功');
          },
          fail: function (err) {
            console.error('地图打开失败', err);
          }
        });


    },
    formatRichText(html) {
        //控制小程序中图片大小
        let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
            console.log(match.search(/style=/gi));
            if (match.search(/style=/gi) == -1) {
                match = match.replace(/\<img/gi, '<img style=""');
            }
            return match;
        });

        newContent = newContent.replace(/style="/gi, '$& max-width:100% !important; ');
        newContent = newContent.replace(/<br[^>]*\/>/gi, '');
        return newContent;
    },
    qiandao(ret){
        var that=this;
        var id=this.data.id;

        wx.showModal({
          title: '签到',
          content: '确认签到？',
          complete: (res) => {
            if (res.confirm) {
                api.post({
                    url: 'meeting/qiandao',
                    data: {id:id},
                    success: data => {

                        wx.showToast({
                          title: data.msg,
                          icon:'none'
                        })
                       that.getinfobyid();
                    },
                });
            }
          }
        })


    },
});
